<?php

namespace app\common\validate;

use think\Validate;

class SellerAppointment extends Validate
{

    /**
     * 验证规则
     */
    protected $rule = [
        'id' => 'require',
        'user_id' => 'require',
        'username' => 'require',
        'phone' => 'require',
        'house_id' => 'require',
        'amount' => 'require',
        'house_password' => 'validHousePassword',
        'photos' => 'validPhotos',
        'view_time' => 'validViewTime',
    ];

    /**
     * 提示消息
     */
    protected $message = [
        "id.require" => "缺少参数id",
        "user_id.require" => "缺少参数用户id",
        "username.require" => "请输入客户姓名",
        "phone.require" => "请输入手机号码",
        "house_id.require" => "缺少参数房屋id",
        "amount.require" => "缺少参数房屋价格",
        "house_password.validHousePassword" => "请输入临时密码",
        "photos.validPhotos" => "请上传带看图片",
        "view_time.validViewTime" => "缺少参数带看时间",
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add' => ['user_id', 'username', 'phone', 'house_id', 'amount'],
        'update' => ['user_id', 'username', 'phone', 'house_id', 'amount', 'house_password', 'photos', 'view_time'],
    ];

    public function validHousePassword($value, $rule, $row)
    {
        if ($row['status'] != 1 && empty($value)) return false;
        return true;
    }

    public function validPhotos($value, $rule, $row)
    {
        if ($row['status'] == 3 && empty($value)) return false;
        return true;
    }

    public function validViewTime($value, $rule, $row)
    {
        if ($row['status'] == 3 && empty($value)) return false;
        return true;
    }

}
